package Operation;

import Book.Book;
import Book.Bookshelf;

import java.util.Scanner;

public class borrowBookOperate implements IOOperation{
    @Override
    public void work(Bookshelf bookshelf) {
        System.out.println("借阅图书........");

        Scanner s = new Scanner(System.in);
        System.out.println("请输入你要借阅的图书：");
        String name = s.nextLine();
        Book[] books = bookshelf.getBookList();
        for (int i = 0; i < bookshelf.getUsedSize(); i++) {
            if(name.equals(books[i].getName()) ) {
                if(books[i].getBorrow()==false) {
                    System.out.println("借阅"+name+"成功！");
                    books[i].setBorrow(true);
                    return;
                }
                System.out.println("借阅失败。"+name+" 已被借出。");
                return;
            }
        }

        System.out.println("借阅失败。"+"馆里还没有这本 "+name+" 书");

    }
}
